//package com.lysj.bhp.coin.job;
//
//
//import com.lysj.bhp.investment.domain.Dividend;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.scheduling.annotation.Scheduled;
//import org.springframework.stereotype.Component;
//
//import java.util.Date;
//import java.util.List;
//
//@Component
//public class DividendJob extends ScheduledContent {
//
//    private static Logger logger = LoggerFactory.getLogger(DividendJob.class);
//
//
//    @Scheduled(cron = "00 00 01 * * ?")
//    public void createDividends() {
//        List<User> users = userRepository.findByBhpcGreaterThan(300);
//        double ethereumToDollar = exchangeRateService.getEthereumToDollar();
//        double bhpcToDallar = exchangeRateService.getBhpcToDollar();
//        users.forEach(user -> {
//            double dividend = user.getBhpc() * bhpcToDallar * (0.15 / 365) / ethereumToDollar;
//            logger.info(user.getUserId() + ":" + user.getBhpc() + "=>" + dividend);
//            user.setDividend(user.getDividend() + dividend);
//
//            Dividend dividendQuery = dividendRepository.findTopByOrderByDividentIdDesc();
//            long nextId = 1L;
//            if (dividendQuery != null) {
//                nextId = dividendQuery.getDividentId() + 1;
//            }
//            Dividend dividendCreate = new Dividend();
//            dividendCreate.setDividentId(nextId);
//            dividendCreate.setUserId(user.getUserId());
//            dividendCreate.setEmail(user.getEmail());
//            dividendCreate.setBhpc(user.getBhpc());
//            dividendCreate.setDividend(dividend);
//            dividendCreate.setCurrentEthereumToDollar(ethereumToDollar);
//            dividendCreate.setCreateTime(new Date());
//
//            userRepository.save(user);
//            dividendRepository.save(dividendCreate);
//        });
//    }
//
//
//}
